########################################################################################
@model[]
########################################################################################

^if( def $form:delete ){ ^oSensus.data.delete[ $.from[houses] $.where[id = $form:delete] ] }

^if( def $form:rent || def $form:buy ){
	$t[^oSensus.data.filter[
		$.select[
			*,
			( SELECT name FROM objectTypeList WHERE id = objectTypeId ) objectType,
			( SELECT name FROM regionList WHERE id = regionId ) region, 
			( SELECT name FROM stationList WHERE id = stationId ) station, 
			( SELECT name FROM contactList WHERE id = contactId ) contact, 
			( SELECT phone FROM contactList WHERE id = contactId ) phone
		]
		$.from[houses]
		$.where[
			^if( def $form:rent ){ $.dealTypeId[ dealTypeId = 1 ] }{ $.dealTypeId[ dealTypeId = 2 ] }
			^if( ^form:price.int(0) ){ $.price[ price < '$form:price' ] }
		]
	]]
}

########################################################################################



########################################################################################
@view[]
########################################################################################

<h1>Дома, коттеджи, дачи</h1>
<form method="post">
	<table>
		<tr>
			<td class="aRight"><label for="objectTypeId">Тип объекта</label></td>
			<td>
				^oSensus.interface.select[
					$.name[objectTypeId]
					$.table[^oSensus.data.table{ SELECT id, name FROM objectTypeList WHERE id IN ( 10,11,12,13 ) ORDER BY name }]
				]
			</td>
			<td class="aRight"><label for="regionId">Регион</label></td>
			<td>
				^oSensus.interface.select[
					$.name[regionId]
					$.table[^oSensus.data.dictionary[regionList]]
				]
			</td>
		</tr>
		<tr>
			<td class="aRight"><label for="rooms">Количество комнат</label></td>
			<td><input name="rooms" id="rooms" value="$form:rooms" /></td>
			<td class="aRight"><label for="stationId">Метро</label></td>
			<td>
				^oSensus.interface.select[
					$.name[stationId]
					$.table[^oSensus.data.dictionary[stationList]]
				]
			</td>
		</tr>
		<tr>
			<td class="aRight"><label for="price">Цена до, в рублях</label></td>
			<td><input name="price" id="price" value="$form:price" /></td>
		</tr>
		<tr>
			<td colspan="4" class="aRight">
				<input type="submit" name="rent" value="Снять" />
				<input type="submit" name="buy" value="Купить" />
			</td>
		</tr>
	</table>
</form>
^if( def $t ){
	<ul>
		^t.menu{
			<li>
				^if( def $t ){
#					^if( $t.objectTypeId == 1 ){
						<h2>${t.rooms}-комнатн^if($t.objectTypeId == 11){ая}{ый} $t.objectType, $t.region, м.$t.station, $t.price рублей в месяц</h2>
							<p>$t.description</p>
						<p>$t.contact, $t.phone</p>
						<form method="post">
							<input type="submit" onclick="return confirm('Удалить предложение?')" value="Удалить" />
							<input type="hidden" name="delete" value="$t.id" />
						</form>
					}
			</li>
		}	
	</ul>
}

########################################################################################